<template>
  <div>
    <Card>

      <Table
        ref="tableLkyApply"
        :data="tableData"
        :columns="columns"
        @on-selection-change="onSelectionChange"
        @on-sort-change="onSortChange"
      />
      <div style="margin: 10px;overflow: hidden">
        <div style="float: right;">
          <Page
            :total="total"
            :current="current"
            :page-size="pageSize"
            @on-page-size-change="changePageSize"
            @on-change="changePage"
            :show-total="true"
            show-sizer
          ></Page>
					<Edit v-model="isOpenEditPage" @updateRow="updateLkyApply"  :LkyApply="editLkyApply"/>
        </div>
      </div>

    </Card>
  </div>
</template>

<script>
import { list } from '@/api/lky/lkyApply'

import { createFormObj, getToken } from '@/libs/util'
// 学院查询、专业查询
import { queryAll } from '@/api/lky/lkyCollege'
import { queryAllM } from '@/api/lky/lkyMajor'

import Edit from './edit.vue'

	
export default {
  name: 'LkyApply',
  components: {
    Edit
  },


  data () {
	  
    return {
      collegeList: [],
      coid: '',
      majorList: [],
      editLkyApply: null,
	  now_time:null ,
	  
      formLkyApply: {
        id: '',
        fife_name: '',
        times: '',
        yettimes: '',
        start_time: '',
        end_time: '',
		fid:'',			
      },

      columns: [
        
        { key: 'file_name', title: '表名', sortable: true },
        { key: 'times', title: '需填次数', sortable: true },
        { key: 'yettimes', title: '已填次数', sortable: true },
        { key: 'start_time', title: '开始时间', sortable: true },
        { key: 'end_time', title: '结束时间', sortable: true },
        {
          title: '操作',
          key: 'action',
          width: 250,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h(
                'Button',
                {
                  props: {
                    type: 'primary',
                    size: 'small',
					disabled:(this.panduan(params)) ,
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
					  console.log(params.row.fid)					 
                      this.editLkyApply = params.row
					  this.fid = params.row.fid
                      this.handleOpenPage('edit')
					  
                    }
                  }
                },
                '申请'
              )
            ])
          }
        }
      ],
      tableData: [],
      total: 0,
      current: 1,
      pageSize: 10,
      isOpenAddPage: false,
      isOpenEditPage: false,
      selection: []
    }
	
  },
  
  
  methods: {
   
    onOpenChangeCollege () {
      queryAll().then(res => {
        this.collegeList = res.data
      })
    },
	panduan(params){
		return !(new Date().getTime() > new Date(params.row.end_time).getTime() && params.row.times > params.row.yettimes)
	},		
    onOpenChangeMajor (coid) {
      queryAllM({ 'coid': this.coid }).then(res => {
        this.majorList = JSON.parse(JSON.stringify(res.data))
      })
    },
    handleSubmit (name) {
      // 查询按钮事件
      this.getLkyApplyList(this.current, this.pageSize)
      this.$Message.success('Success!')
    },
    handleReset (name) {
      // 重置按钮事件
      this.$refs[name].resetFields()
    },
    handleOpenPage (name) {
      // 打开页面事件(添加页,编辑页...)
      // === 是地址相同
      // == 是值相同
      if (name == 'edit') this.isOpenEditPage = true
    },
    addLkyApply (row) {
      this.tableData.push(row)
      this.getLkyApplyList(this.current, this.pageSize)
    },
    updateLkyApply (row) {
      this.$set(this.tableData, row._index, row)
    },

    getLkyApplyList (current, pageSize, paras) {
      let para = { pageNumber: current, pageSize: pageSize }
      if (paras) Object.assign(para, paras)
      // 后台的持久层框架 是？？ mybatis? // 这是 jfinal aaaa
      // 没用过这个呀，可以再controllor  里面选择走不同的 查询// 这个里面没有

		//将uid返回给后台
	  Object.assign(para,{uid:getToken()})
	  console.log("++++++++++++++++++++")
	  console.log(para)

		

      list(this.handleRequestParams(para)).then(res => {
        this.tableData = res.list
        this.current = parseInt(res.pageNumber)
        this.pageSize = parseInt(res.pageSize)
        this.total = parseInt(res.totalRow)
      })
    },
    handleRequestParams (para) {
      Object.assign(para, createFormObj(this.formLkyApply, 'LkyApply'))
      return para
    },
    exportExcel () {
      this.$refs.tableLkyApply.exportCsv({
        filename: `table-${new Date().valueOf()}.csv`
      })
    },
    changePage (pageNumber) {
      this.getLkyApplyList(pageNumber, this.pageSize)
    },
    changePageSize (pageSize) {
      this.getLkyApplyList(this.current, pageSize)
    },
    remove (index) {
      this.data6.splice(index, 1)
    },
    onSelectionChange (selection) {
      this.selection = selection
    },
    onSortChange (obj) {
      if (obj.order === 'normal') {
        this.getLkyApplyList(1, this.pageSize)
      } else {
        this.getLkyApplyList(1, this.pageSize, {
          field: obj.key,
          order: obj.order
        })
      }
    }
  },

  mounted () {
		this.uid =getToken(),
    this.getLkyApplyList(this.current, this.pageSize)
  }
}

</script>

<style>
</style>
